﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class adm_vlg_adminOrderDetails : System.Web.UI.Page
{
    VLGDataContext _db8 = new VLGDataContext();
    Order order = null;
    protected void Page_Load(object sender, EventArgs e)
    {

        FillData();

    }
    public void FillData()
    {
        if (order == null)
        {
            order = _db8.Orders.Single(c => c.idDH == (Request.QueryString["id"]));

        }
        lblKhachHang.Text = order.VLGAccount.UsernameE;
        lblNgaydat.Text = string.Format("{0:dd/MM/yyyy}", order.NgayDat);
        lblNgayGiao.Text = string.Format("{0:dd/MM/yyyy}", order.NgayGiao);
        lblCongViec.Text = order.Gig.TenCongViec;
        hdId.Value = order.idDH.ToString();
        if (order.DaThanhToan==true)
        {
            Button1.Enabled = false;
            Button2.Enabled = false;
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string orderId = hdId.Value;
        //order = _db8.Orders.Single(c => c.idDH == orderId);
        if ((order.SellerConfirm==true) && (order.CustomerConfirm==true)&&(order.DaThanhToan==false))
        {

            order.DaThanhToan = true;
            var kh = order.Gig.VLGAccount;
            kh.soTien = kh.soTien + 4;
            var chuyenKhoan = new YeuCauChuyenKhoan();
            chuyenKhoan.ngay = DateTime.Now;
            chuyenKhoan.soTien = 4;
            chuyenKhoan.idAcc = order.Gig.idAcc;
            chuyenKhoan.status = true;
            chuyenKhoan.type = (int)EnumChuyenKhoanType.ThanhToanDH;
            chuyenKhoan.isActive = true;
            chuyenKhoan.idDH = order.idDH;
            _db8.YeuCauChuyenKhoans.InsertOnSubmit(chuyenKhoan);
            _db8.SubmitChanges();
            Button1.Enabled = false;
            Button2.Enabled = false;
            pnMessage.Visible = true;
            lrtMessage.Text = "Đã thanh toán thành công";
        }
        #region
        //PaypalProcess _paypalProcess = new PaypalProcess();
        //string returnURL = "http://localhost:23910/ViecLamGap/Default5.aspx";
        //string returnCancelURL = System.Web.HttpContext.Current.Request.Url.AbsoluteUri; 
        //string server="https://www.sandbox.paypal.com/cgi-bin/webscr?";
        //string business="nhathn_1342581970_biz@gmail.com";
        //string itemName=order.Gig.TenCongViec;
        //int itemNumber = order.Gig.idGig;
        //int amount=4;
        //Response.Redirect(_paypalProcess.GetPaypalProcess(returnURL, returnCancelURL, server, business, itemName,itemNumber, amount));
        #endregion


    }
    protected void btnReturn_Click(object sender, EventArgs e)
    {
        Response.Redirect("adminOrders.aspx");
    }

}